package edu.uc.ui.ctrl25;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import edu.uc.bean.JvmData;

@Repository("JvmDataAction")
@Scope("prototype")
public class JvmDataAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JvmData jData = new JvmData();
	
	public JvmData getjData() {
		return jData;
	}
	public void setjData(JvmData jData) {
		this.jData = jData;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
//	private Map<String,Object> jsonMap= new HashMap<String,Object>();  
//	  
//    public Map<String, Object> getJsonMap() {  
//        return jsonMap;  
//    }  
//    public void setJsonMap(Map<String, Object> jsonMap) {  
//        this.jsonMap = jsonMap;  
//    }  
	public String show() throws Exception{
		MemoryUsage mu = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); 
		 
		long getCommitted = mu.getCommitted(); 
		 
		long getInit = mu.getInit(); 
		 
		long getUsed = mu.getUsed(); 
		 
		long max = mu.getMax(); 
		System.out.println(getUsed);
		System.out.println(max);
//		jsonMap.put("user", getUsed);
//		jsonMap.put("max", max);
		jData.setHeapMemoryUsageUsed(getUsed);
		jData.setHeapMemoryUsageMax(max);
		jData.setMemoryBi(getUsed*1.0/max*1.0);
		jData.setNow_data(new Date());
//		jvmData.setNoheapMemoryUsageUsed(mm1.getNonHeapMemoryUsage().getUsed());
//		jvmData.setNoheapMemoryUsageMax(mm1.getNonHeapMemoryUsage().getMax());
		return "success";	
	}
	
	public String list() throws Exception{
		return "list";
	}
}
